package com.cn.zmc.design.chian.disruptor.publish;


import com.cn.zmc.design.chian.domain.Trade;
import com.lmax.disruptor.RingBuffer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class TradeTwoPublish extends AbstractPublish{

    @Autowired
    @Qualifier("tradeTwoRingBuffer")
    private RingBuffer<Trade> tradeTwoRingBuffer;

    @Override
    @Async
    void publish() {

        for(int j = 0; j<100; j++) {
            long sequence = tradeTwoRingBuffer.next();
            try {
                Trade trade = tradeTwoRingBuffer.get(sequence);
                trade.setId(UUID.randomUUID().toString());
            } catch (Exception e) {

            } finally {
                tradeTwoRingBuffer.publish(sequence);
            }
        }
    }
}
